package hb.rj.demand.controller;

import hb.rj.demand.entity.Students;
import hb.rj.demand.service.StudentsService;

import org.springframework.context.annotation.ComponentScan;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;



@RestController
@RequestMapping("/")
@ComponentScan("hb.rj.demand.entity")
public class StudentsController{
    @Resource
    StudentsService service;

    /**
     * 插入学生信息
     */
    @PostMapping(value = "/insert",produces = "application/json;charset=UTF-8")
    public String insert(Students students){
        int i = service.insertStudentInfo(students);
        return students.getName()+"添加成功";
    }

    /**
     * 修改学生信息
     */
    @PostMapping(value = "/modify",produces = "application/json;charset=UTF-8")
    public String modify(Students students){
        int i = service.modifyStudentInfo(students);
        if(i>=0){
            return "信息修改成功";
        }else
            return "信息修改失败";
    }

    /**
     * 根据学生姓名查找学生信息
     */
    @GetMapping(value = "/find",produces = "application/json;charset=UTF-8")
    public Students find(String name){
        Students students=service.findByNameInfo(name);
        return students;
    }

    /**
     * 根据学生姓名删除学生信息
     */
    @PostMapping("/delete")
    public int delete(String name){
        int i=service.deleteByNameInfo(name);
        return i;
    }
}
